import {deepClone} from 'nc-lightapp-front';
import checkDeleteLine from "./checkDeleteLine";
import editLine from "./editLine";
import changeLine from "./changeLine";

function handleTableAct(id, record, index) {
    switch (id) {
        case 'delete':
            checkDeleteLine.call(this, record, index)
            break;
        case 'edit':
            this.editType = 3;
            editLine.call(this, record, index)
            break;
        case 'change':
            this.editType = 4;
            changeLine.call(this, record, index)
            break;
        default:
            break;
    }
}

// 初始化处理template数据
export default function addAction() {
    const {buttons, button} = this.props;
    let _that = this;
    let meta = this.props.meta.getMeta();
    if (meta['hi_psndoc_part'].items.findIndex(item => item.itemtype === 'customer') > -1) return;
    const result = [];
    buttons.forEach(btn => {
        if(btn.area === 'table'){
            result.push(btn.key)
        }
    })
    meta['hi_psndoc_part'].items.push({
        itemtype: 'customer',
        width: '160px',
        label: this.props.json['hi6007-000029'],/* 国际化处理： 操作*/
        visible: true,
        fixed: 'right',
        attrcode: 'opr',
        render: (text, record, index) => {
            return (
                <div>
                    {button.createOprationButton(
                        result,
                        {
                            area: 'table',
                            buttonLimit: 3,
                            onButtonClick: (props, id, e) => {
                                handleTableAct.call(_that, id, record, index)
                            }
                        }
                    )}
                    {/*{
                        buttons.findIndex(btn => btn.key === 'delete') > -1 ?
                            <a
                                href="javascript:void(0)"
                                className="operator-btn"
                                onClick={() => {
                                    checkDeleteLine.call(_that, record, index)
                                }}
                            >
                                {this.props.json['hi6007-000031']} 国际化处理： 删除
                            </a> : null
                    }
                    {
                        buttons.findIndex(btn => btn.key === 'edit') > -1 ?
                            <a
                                href="javascript:void(0)"
                                className="operator-btn"
                                onClick={() => {
                                    this.editType = 3;
                                    editLine.call(_that, record, index)
                                }}
                            >
                                {this.props.json['hi6007-000030']} 国际化处理： 修改
                            </a> : null
                    }
                    {
                        buttons.findIndex(btn => btn.key === 'change') > -1 ?
                            <a
                                href="javascript:void(0)"
                                className="operator-btn"
                                onClick={() => {
                                    this.editType = 4;
                                    changeLine.call(_that, record, index)
                                }}
                            >
                                {this.props.json['hi6007-000113']} 国际化处理： 变更
                            </a> : null
                    }*/}
                </div>
            );
        }
    });
    this.props.meta.setMeta(meta);
}
